//
//  ListVCCell.m
//  EducationAdminClient
//
//  Created by kwsdzjx on 15/11/26.
//  Copyright © 2015年 周佳兴. All rights reserved.
//

#import "ListVCCell.h"
#import "Masonry.h"
#import "UIColor+CL.h"
#define LEFT 30/2
#define BTNWITH 22
#define BTNHEIGHT 22
#define WITHBTNRIGHT 5
#define LABELHEIGHT 50
@implementation ListVCCell
-(instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:reuseIdentifier];
    if(self){
        UIView *superView = [self createUI];
        [self.contentView addSubview:superView];
        [superView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView.mas_left);
            make.top.equalTo(self.contentView.mas_top);
            make.right.equalTo(self.contentView.mas_right);
            make.bottom.equalTo(self.contentView.mas_bottom);
        }];
        
    }
    return self;
}

-(UIView *)createUI{
    _baseView = [[UIView alloc]init];
    
    _selctButton = [[UIImageView alloc]init];
//    _selctButton.backgroundColor = [UIColor grayColor];
    
    [_baseView addSubview:_selctButton];
    
    _teLabel = [[UILabel alloc]init];
    [_baseView addSubview:_teLabel];
    
    _imgView = [[UIImageView alloc]init];
    [_baseView addSubview:_imgView];
    
    UIImageView *lineImg = [[UIImageView alloc]init];
    [_baseView addSubview:lineImg];
    
    [_selctButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(LEFT));
        make.centerY.equalTo(_baseView.mas_centerY);
        make.width.equalTo(@(0));
        make.height.equalTo(@(0));
    }];
    
    [_teLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_selctButton.mas_right).offset(WITHBTNRIGHT);
        make.centerY.equalTo(_baseView.mas_centerY);
        make.right.equalTo(_imgView.mas_left).offset(30/2);
        make.height.equalTo(@(LABELHEIGHT));
    }];

    [_imgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(@(-LEFT));
        make.centerY.equalTo(_baseView.mas_centerY);
        make.width.equalTo(@(17/2));
        make.height.equalTo(@(30/2));
    }];
    
    [lineImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(_baseView.mas_right);
        make.bottom.equalTo(_baseView.mas_bottom);
        make.left.equalTo(_baseView.mas_left);
        make.height.equalTo(@(1));
    }];

    lineImg.backgroundColor = [UIColor colorWithHex:0xd1d1d1];
//    _imgView.backgroundColor = [UIColor redColor];
    [_selctButton setImage:[UIImage imageNamed:@"椭圆-1-拷贝-3"]];
//    _teLabel.backgroundColor = [UIColor redColor];
    _imgView.image = [UIImage imageNamed:@"形状-19"];
    _teLabel.text = @"未知";
    _teLabel.textColor = [UIColor colorWithHex:0x5c5c5c];
    _teLabel.font = [UIFont systemFontOfSize:34/2];
    return _baseView;
}
-(void)setImage:(NSString *)image{
    _image = image;
    _teLabel.text = image;
    if(!self.longSelected){
        [_selctButton mas_updateConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(@(LEFT));
//        make.centerY.equalTo(@(0));
        make.width.equalTo(@(0));
        make.height.equalTo(@(0));
    }];
//        [_teLabel mas_updateConstraints:^(MASConstraintMaker *make) {
//            make.left.equalTo(_selctButton.mas_right).offset(WITHBTNRIGHT);
//            make.centerY.equalTo(_baseView.mas_centerY);
//            make.right.equalTo(_imgView.mas_left).offset(5);
//            make.height.equalTo(@(LABELHEIGHT));
//        }];

    }else{
        [_selctButton mas_updateConstraints:^(MASConstraintMaker *make) {
            make.width.equalTo(@(BTNWITH));
            make.height.equalTo(@(BTNHEIGHT));
        }];
        
//        [_teLabel mas_updateConstraints:^(MASConstraintMaker *make) {
//            make.left.equalTo(_selctButton.mas_right).offset(WITHBTNRIGHT);
//            make.centerY.equalTo(_baseView.mas_centerY);
//            make.right.equalTo(_imgView.mas_left).offset(5);
//            make.height.equalTo(@(LABELHEIGHT));
//        }];

    }
}
-(void)setSelctButton{
    if (!self.selectedMore) {
        [_selctButton setImage:[UIImage imageNamed:@"椭圆-1-拷贝-3"]];
//        _selctButton.image = [UIImage imageNamed:@""];
    }else if(self.selectedMore){
        [_selctButton setImage:[UIImage imageNamed:@"形状-20-拷贝"]];
        //        _selctButton.image = [UIImage imageNamed:@""];
    }
}
@end
